<template>
	<view class="container">
		<view class="header">
			<text class="title">🤖 AI健康分析</text>
			<text class="subtitle">基于您的健康数据，AI将为您提供专业的健康分析</text>
		</view>

		<!-- 加载动画 -->
		<view v-if="isAnalyzing">
			<view class="loading-overlay">
				<view class="loading-content">
					<view class="loading-icon">🤖</view>
					<text class="loading-text">AI正在分析您的健康数据...</text>
					<text class="loading-subtext">请稍候，这可能需要几秒钟</text>
				</view>
			</view>
		</view>

		<!-- 暂无健康数据 -->
		<view class="data-check" v-else-if="!healthData">
			<view class="check-icon">📊</view>
			<text class="check-title">暂无健康数据</text>
			<text class="check-desc">请先填写健康数据，然后进行AI分析</text>
			<button class="check-btn" @click="goToHealth">去填写数据</button>
		</view>

		<!-- 分析结果 -->
		<view v-else-if="analysisReady && (healthData || (aiAnalysis && Object.keys(aiAnalysis).length > 0))">
			<view class="analysis-content">
				<view v-if="analysisPartial" class="warn-tip">⚠️ 部分数据未获取到，分析结果可能不完整</view>
				<view v-if="isHistoricalData" class="history-tip">📚 显示历史分析记录</view>
				<!-- 健康评分 -->
				<view class="score-section">
					<view class="score-circle">
						<text class="score-number">{{healthScore}}</text>
						<text class="score-label">健康评分</text>
					</view>
					<text class="score-desc">{{aiAnalysis.scoreDescription || getScoreDescription()}}</text>
				</view>

				<!-- 详细分析 -->
				<view class="analysis-section">
					<text class="section-title">📊 详细分析</text>
					<!-- BMI分析 -->
					<view class="analysis-item">
						<view class="item-header">
							<text class="item-title">BMI分析</text>
							<text class="item-value">{{isHistoricalData ? '历史数据' : (healthData ? healthData.bmi : '已分析')}}</text>
						</view>
						<view class="item-content">
							<text class="item-desc">{{aiAnalysis.bmiAnalysis || getBMIAnalysis()}}</text>
						</view>
					</view>
					<!-- 血压分析 -->
					<view class="analysis-item">
						<view class="item-header">
							<text class="item-title">血压分析</text>
							<text class="item-value">{{isHistoricalData ? '历史数据' : (healthData ? healthData.bloodPressureStatus : '已分析')}}</text>
						</view>
						<view class="item-content">
							<text class="item-desc">{{aiAnalysis.bpAnalysis || getBloodPressureAnalysis()}}</text>
						</view>
					</view>
					<!-- 生活习惯分析 -->
					<view class="analysis-item">
						<view class="item-header">
							<text class="item-title">生活习惯评估</text>
							<text class="item-value">{{getLifestyleScore()}}</text>
						</view>
						<view class="item-content">
							<text class="item-desc">{{aiAnalysis.lifestyleAnalysis || getLifestyleAnalysis()}}</text>
						</view>
					</view>
					<!-- 主要健康风险点 -->
					<view class="analysis-item" v-if="aiAnalysis.healthRisks">
						<view class="item-header">
							<text class="item-title">主要健康风险点</text>
							<text class="item-value">⚠️</text>
						</view>
						<view class="item-content">
							<text class="item-desc">{{aiAnalysis.healthRisks}}</text>
						</view>
					</view>
					<!-- 改善建议 -->
					<view class="analysis-item" v-if="aiAnalysis.improvementAdvice">
						<view class="item-header">
							<text class="item-title">改善建议</text>
							<text class="item-value">💡</text>
						</view>
						<view class="item-content">
							<text class="item-desc">{{aiAnalysis.improvementAdvice}}</text>
						</view>
					</view>
				</view>

				<!-- AI建议 -->
				<view class="ai-advice-section">
					<text class="section-title">💡 AI智能建议</text>
					<view class="advice-list">
						<view class="advice-item" v-for="(advice, index) in aiAdvice" :key="index">
							<view class="advice-icon">{{advice.icon}}</view>
							<view class="advice-content">
								<text class="advice-title">{{advice.title}}</text>
								<text class="advice-desc">{{advice.description}}</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 重新分析按钮 -->
				<view class="button-container">
					<button class="analyze-btn" @click="performAnalysis">开始分析</button>
				</view>

				<!-- 连接状态提示 -->
				<view class="connection-status" v-if="connectionError">
					<text class="status-text">⚠️ {{connectionError}}</text>
					<text class="status-hint">请检查本地API服务是否正常运行</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { healthAPI, parseAIResponse, analysisAPI } from '../../utils/api.js'
	
	export default {
		data() {
			return {
				healthData: null,
				healthScore: 0,
				aiAdvice: [],
				aiAnalysis: {},
				isAnalyzing: false,
				connectionError: '',
				analysisReady: false,
				analysisPartial: false,
				userInfo: null, // 用户信息
				isLoadingCloudData: false, // 云端数据加载状态
				isHistoricalData: false, // 是否为历史数据
				lastAnalysisTimestamp: null // 上次分析的健康数据时间戳
			}
		},
		onLoad() {
			const userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				uni.redirectTo({ url: '/pages/login/login' })
				return
			}
			this.userInfo = userInfo
			this.loadHealthData()
			// 读取本地lastAnalysisTimestamp
			this.lastAnalysisTimestamp = uni.getStorageSync('lastAnalysisTimestamp') || null
			if (this.isAnalyzing) {
				console.log('[AI分析] onLoad: 正在分析中，跳过')
				return
			}
			const currentHealthData = uni.getStorageSync('healthData')
			if (currentHealthData && currentHealthData.timestamp !== this.lastAnalysisTimestamp) {
				console.log('[AI分析] onLoad: 触发分析')
				this.healthData = currentHealthData
				this.isHistoricalData = false
				this.lastAnalysisTimestamp = currentHealthData.timestamp // 立即设置，防止死循环
				uni.setStorageSync('lastAnalysisTimestamp', this.lastAnalysisTimestamp)
				this.performAnalysis()
			} else {
				console.log('[AI分析] onLoad: 加载云端历史分析')
				this.loadCloudAnalysis()
			}
		},
		onShow() {
			const userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				uni.redirectTo({ url: '/pages/login/login' })
				return
			}
			this.userInfo = userInfo
			this.loadHealthData()
			// 读取本地lastAnalysisTimestamp
			this.lastAnalysisTimestamp = uni.getStorageSync('lastAnalysisTimestamp') || null
			if (this.isAnalyzing) {
				console.log('[AI分析] onShow: 正在分析中，跳过')
				return
			}
			const currentHealthData = uni.getStorageSync('healthData')
			if (currentHealthData && currentHealthData.timestamp !== this.lastAnalysisTimestamp) {
				console.log('[AI分析] onShow: 触发分析')
				this.healthData = currentHealthData
				this.isHistoricalData = false
				this.lastAnalysisTimestamp = currentHealthData.timestamp // 立即设置，防止死循环
				uni.setStorageSync('lastAnalysisTimestamp', this.lastAnalysisTimestamp)
				this.performAnalysis()
			} else {
				console.log('[AI分析] onShow: 加载云端历史分析')
				this.loadCloudAnalysis()
			}
		},
		methods: {
			// 加载云端分析结果
			async loadCloudAnalysis() {
				if (!this.userInfo || this.isLoadingCloudData) return
				this.isLoadingCloudData = true
				this.isAnalyzing = true // 显示加载动画
				try {
					const cloudResult = await analysisAPI.getAnalysis(this.userInfo.userId)
					console.log('云端接口返回:', cloudResult)
					let parsedHealthData = cloudResult && cloudResult.healthData
					if (typeof parsedHealthData === 'string') {
						try {
							parsedHealthData = JSON.parse(parsedHealthData)
						} catch (e) {
							parsedHealthData = {}
						}
					}
					console.log('解析后 healthData:', parsedHealthData)
					this.healthData = parsedHealthData
					// 兼容处理aiAnalysis
					const cloudAiAnalysis = typeof cloudResult.aiAnalysis === 'string'
						? JSON.parse(cloudResult.aiAnalysis)
						: cloudResult.aiAnalysis || {}
					// 兼容处理aiAdvice
					let adviceArr = typeof cloudResult.aiAdvice === 'string'
						? JSON.parse(cloudResult.aiAdvice)
						: cloudResult.aiAdvice || []
					const cloudAiAdvice = Array.isArray(adviceArr) ? adviceArr : []

					this.aiAnalysis = cloudAiAnalysis
					this.aiAdvice = cloudAiAdvice
					this.healthScore = cloudResult.healthScore || 0
					this.isHistoricalData = true
					if (this.healthData && typeof this.healthData === 'object' && Object.keys(this.healthData).length > 0) {
						this.analysisReady = true
					} else {
						this.analysisReady = false
					}
					this.analysisPartial = false
					this.isAnalyzing = false // 数据回来后关闭加载动画
					this.$nextTick(() => {
						this.$forceUpdate && this.$forceUpdate()
					})
					console.log('历史数据赋值成功:', {
						healthData: this.healthData,
						healthScore: this.healthScore,
						aiAnalysis: this.aiAnalysis,
						aiAdvice: this.aiAdvice
					})
					console.log('healthData keys:', Object.keys(this.healthData))
					uni.showToast({ title: '已加载云端分析', icon: 'success' })
				} catch (e) {
					console.error('历史数据解析失败:', e, cloudResult)
					this.analysisReady = false
					this.healthData = null
					this.healthScore = 0
					this.aiAnalysis = {}
					this.aiAdvice = []
					this.isHistoricalData = false
					uni.showToast({ title: '历史数据解析失败', icon: 'none' })
				} finally {
					this.isLoadingCloudData = false
				}
			},
			
			// 加载历史分析记录（当没有当前健康数据时）
			async loadHistoricalAnalysis() {
				if (!this.userInfo) return
				
				try {
					console.log('加载用户历史分析记录...')
					const historicalResult = await analysisAPI.getAnalysis(this.userInfo.userId)
					
					if (historicalResult && historicalResult.healthData) {
						// 解析历史数据
						const historicalHealthData = JSON.parse(historicalResult.healthData)
						const historicalAiAnalysis = JSON.parse(historicalResult.aiAnalysis)
						const historicalAiAdvice = JSON.parse(historicalResult.aiAdvice)
						
						// 使用历史分析结果
						this.healthScore = historicalResult.healthScore
						this.aiAnalysis = historicalAiAnalysis
						this.aiAdvice = historicalAiAdvice
						this.analysisReady = true
						this.analysisPartial = false
						this.isAnalyzing = false
						
						// 显示历史数据提示
						uni.showToast({
							title: '已加载历史分析',
							icon: 'success'
						})
						
						console.log('使用历史分析结果:', this.aiAnalysis)
					} else {
						// 没有历史数据，显示提示
						this.analysisReady = false
						this.analysisPartial = false
						this.isAnalyzing = false
						this.healthScore = 0
						this.aiAnalysis = {}
						this.aiAdvice = []
						
						uni.showToast({
							title: '暂无分析记录',
							icon: 'none'
						})
					}
				} catch (error) {
					console.error('加载历史分析记录失败:', error)
					// 加载失败，显示提示
					this.analysisReady = false
					this.analysisPartial = false
					this.isAnalyzing = false
					this.healthScore = 0
					this.aiAnalysis = {}
					this.aiAdvice = []
					
					uni.showToast({
						title: '加载历史记录失败',
						icon: 'none'
					})
				}
			},
			
			// 加载本地分析结果
			loadLocalAnalysis() {
				const last = uni.getStorageSync('lastAnalysis')
				if (last && JSON.stringify(last.healthData) === JSON.stringify(this.healthData)) {
					this.healthScore = last.healthScore
					this.aiAnalysis = last.aiAnalysis
					this.aiAdvice = last.aiAdvice
					this.analysisReady = true
					this.analysisPartial = false
					this.isAnalyzing = false
					console.log('使用本地缓存分析结果')
				} else {
					// 本地也无匹配数据，需要重新分析
					this.performAnalysis()
				}
			},
			
			// 保存分析结果到云端
			async saveAnalysisToCloud(healthDataParam) {
				const healthDataToSave = healthDataParam || this.healthData;
				if (!this.userInfo || !this.analysisReady) {
					console.log('跳过保存到云端：用户信息或分析结果不完整')
					return
				}
				
				try {
					console.log('开始保存分析结果到云端...')
					console.log('用户ID:', this.userInfo.userId)
					console.log('健康评分:', this.healthScore)
					console.log('分析数据:', this.aiAnalysis)
					
					const result = await analysisAPI.saveAnalysis(this.userInfo.userId, {
						healthData: healthDataToSave,
						healthScore: this.healthScore,
						aiAnalysis: this.aiAnalysis,
						aiAdvice: this.aiAdvice
					})
					
					console.log('云端保存响应:', result)
					
					if (result.success) {
						console.log('分析结果已保存到云端（覆盖历史记录）')
						if (result.overwritten) {
							console.log('✅ 成功覆盖了历史记录')
						} else {
							console.log('✅ 创建了新的分析记录')
						}
					} else {
						console.error('保存分析结果到云端失败:', result.error)
						uni.showToast({
							title: '云端保存失败',
							icon: 'none'
						})
					}
				} catch (error) {
					console.error('保存分析结果到云端异常:', error)
					uni.showToast({
						title: '云端保存异常',
						icon: 'none'
					})
				}
			},

			loadHealthData() {
				const data = uni.getStorageSync('healthData')
				if (data) {
					this.healthData = data
				}
			},
			goToHealth() {
				uni.switchTab({
					url: '/pages/health/health'
				})
			},
			async performAnalysis() {
				// 登录校验
				const userInfo = uni.getStorageSync('userInfo')
				if (!userInfo) {
					uni.redirectTo({ url: '/pages/login/login' })
					return
				}

				if (!this.healthData) {
					uni.showToast({
						title: '请先填写健康数据',
						icon: 'none'
					})
					return
				}

				this.isAnalyzing = true
				this.connectionError = ''
				
				// 重置分析结果
				this.healthScore = 0
				this.aiAnalysis = {}
				this.aiAdvice = []
				this.isHistoricalData = false // 重置历史数据标志
				this.analysisReady = false // 重置分析完成状态
				this.analysisPartial = false

				const analyzedHealthData = { ...this.healthData };

				try {
					console.log('[AI分析] performAnalysis触发，healthData:', this.healthData, 'lastAnalysisTimestamp:', this.lastAnalysisTimestamp)
					console.log('开始AI健康分析...')
					
					// 并行执行健康分析和建议获取
					this.analysisReady = false
					this.analysisPartial = false
					const [analysisResult, adviceResult] = await Promise.allSettled([
						healthAPI.analyzeHealth(this.healthData),
						healthAPI.getPersonalizedAdvice(this.healthData)
					])
					
					console.log('所有AI请求完成')
					
					// 处理健康分析结果
					if (analysisResult.status === 'fulfilled' && analysisResult.value.success) {
						const parsedAnalysis = parseAIResponse.parseHealthAnalysis(analysisResult.value.content)
						
						this.healthScore = parsedAnalysis.healthScore
						this.aiAnalysis = {
							scoreDescription: parsedAnalysis.scoreDescription,
							bmiAnalysis: parsedAnalysis.bmiAnalysis,
							bpAnalysis: parsedAnalysis.bpAnalysis,
							lifestyleAnalysis: parsedAnalysis.lifestyleAnalysis,
							healthRisks: parsedAnalysis.healthRisks,
							improvementAdvice: parsedAnalysis.improvementAdvice
						}
						
						console.log('健康分析解析完成:', this.aiAnalysis)
						this.analysisReady = true
						this.analysisPartial = false
					} else {
						console.error('健康分析失败:', analysisResult.reason || analysisResult.value?.error)
						// 使用本地分析作为备选
						this.performLocalAnalysis()
					}

					// 处理建议结果
					if (adviceResult.status === 'fulfilled' && adviceResult.value.success) {
						this.aiAdvice = parseAIResponse.parseAdvice(adviceResult.value.content)
						console.log('建议解析完成:', this.aiAdvice)
						this.analysisReady = true
						this.analysisPartial = false
					} else {
						console.error('建议获取失败:', adviceResult.reason || adviceResult.value?.error)
						// 使用默认建议作为备选
						this.generateDefaultAdvice()
					}

					// 检查是否有任何请求成功
					const allSuccess = (analysisResult.status === 'fulfilled' && analysisResult.value.success)
								&& (adviceResult.status === 'fulfilled' && adviceResult.value.success)
					const hasAnySuccess = (analysisResult.status === 'fulfilled' && analysisResult.value.success)
								|| (adviceResult.status === 'fulfilled' && adviceResult.value.success)
					if (allSuccess) {
						console.log('[AI分析] allSuccess，分析成功')
						this.analysisReady = true
						this.analysisPartial = false
						// 缓存本次分析结果到本地
						uni.setStorageSync('lastAnalysis', {
							healthData: this.healthData,
							healthScore: this.healthScore,
							aiAnalysis: this.aiAnalysis,
							aiAdvice: this.aiAdvice
						})
						// 保存到云端
						await this.saveAnalysisToCloud(analyzedHealthData)
						uni.showToast({
							title: '分析完成',
							icon: 'success'
						})
					} else if (hasAnySuccess) {
						console.log('[AI分析] hasAnySuccess，部分成功')
						this.analysisReady = true
						this.analysisPartial = true
						// 缓存本次分析结果到本地
						uni.setStorageSync('lastAnalysis', {
							healthData: this.healthData,
							healthScore: this.healthScore,
							aiAnalysis: this.aiAnalysis,
							aiAdvice: this.aiAdvice
						})
						// 部分成功也保存到云端
						await this.saveAnalysisToCloud(analyzedHealthData)
						
						uni.showToast({
							title: '分析完成，但部分数据未获取到',
							icon: 'none'
						})
					} else {
						console.log('[AI分析] 所有请求都失败')
						this.connectionError = '无法连接到AI服务，已使用本地分析'
						this.analysisReady = false
						this.analysisPartial = false
						uni.showToast({
							title: '使用本地分析',
							icon: 'none'
						})
					}
					
				} catch (error) {
					console.error('[AI分析] catch异常:', error)
					this.connectionError = '分析过程出错，已使用本地分析'
					this.analysisReady = false
					this.analysisPartial = false
					this.performLocalAnalysis()
					uni.showToast({
						title: '使用本地分析',
						icon: 'none'
					})
				} finally {
					this.isAnalyzing = false
				}
			},
			performLocalAnalysis() {
				// 本地分析作为备选方案
				this.calculateHealthScore()
				this.generateDefaultAdvice()
				this.analysisReady = true
				this.analysisPartial = false
			},
			calculateHealthScore() {
				let score = 100
				const data = this.healthData

				// BMI评分
				const bmi = parseFloat(data.bmi)
				if (bmi < 18.5 || bmi > 24.9) {
					score -= 20
				} else if (bmi < 20 || bmi > 23) {
					score -= 10
				}

				// 血压评分
				if (data.bloodPressureStatus === '高血压') {
					score -= 25
				} else if (data.bloodPressureStatus === '高血压前期') {
					score -= 15
				} else if (data.bloodPressureStatus === '正常偏高') {
					score -= 5
				}

				// 生活习惯评分
				if (data.exercise === '30分钟以下') score -= 15
				if (data.sleep === '6小时以下') score -= 10
				if (data.smoke === '经常吸烟') score -= 20
				else if (data.smoke === '偶尔吸烟') score -= 10

				this.healthScore = Math.max(0, Math.min(100, score))
			},
			getScoreDescription() {
				if (this.healthScore >= 90) return '优秀 - 您的健康状况很好！'
				else if (this.healthScore >= 80) return '良好 - 继续保持健康的生活方式'
				else if (this.healthScore >= 70) return '一般 - 有一些需要改善的地方'
				else if (this.healthScore >= 60) return '需关注 - 建议及时调整生活习惯'
				else return '需重视 - 建议咨询专业医生'
			},
			getBMIAnalysis() {
				if (!this.healthData) return '暂无数据'
				const bmi = parseFloat(this.healthData.bmi)
				if (bmi < 18.5) {
					return '您的体重偏轻，建议适当增加营养摄入，进行力量训练来增加肌肉质量。'
				} else if (bmi >= 18.5 && bmi <= 24.9) {
					return '您的体重在正常范围内，请继续保持健康的生活方式。'
				} else if (bmi >= 25 && bmi <= 29.9) {
					return '您的体重略高，建议适当控制饮食，增加运动量。'
				} else {
					return '您的体重偏高，建议制定减重计划，必要时咨询营养师。'
				}
			},
			getBloodPressureAnalysis() {
				if (!this.healthData) return '暂无数据'
				const status = this.healthData.bloodPressureStatus
				if (status === '正常') {
					return '您的血压正常，请继续保持良好的生活习惯。'
				} else if (status === '正常偏高') {
					return '您的血压略高，建议减少盐分摄入，增加运动。'
				} else if (status === '高血压前期') {
					return '您的血压处于高血压前期，建议定期监测，调整生活方式。'
				} else {
					return '您的血压偏高，建议及时就医，遵医嘱进行治疗。'
				}
			},
			getLifestyleScore() {
				if (!this.healthData) return '暂无数据'
				let score = 100
				const data = this.healthData

				if (data.exercise === '30分钟以下') score -= 30
				if (data.sleep === '6小时以下') score -= 20
				if (data.smoke === '经常吸烟') score -= 40
				else if (data.smoke === '偶尔吸烟') score -= 20

				if (score >= 80) return '良好'
				else if (score >= 60) return '一般'
				else return '需改善'
			},
			getLifestyleAnalysis() {
				if (!this.healthData) return '暂无数据'
				const data = this.healthData
				let analysis = ''

				if (data.exercise === '30分钟以下') {
					analysis += '运动量不足，建议每天进行30分钟以上的中等强度运动。'
				}
				if (data.sleep === '6小时以下') {
					analysis += '睡眠时间不足，建议保证7-8小时的充足睡眠。'
				}
				if (data.smoke !== '不吸烟') {
					analysis += '吸烟对健康有害，建议戒烟或减少吸烟频率。'
				}

				return analysis || '您的生活习惯良好，请继续保持。'
			},
			generateDefaultAdvice() {
				this.aiAdvice = []
				const data = this.healthData

				// 基于BMI的建议
				const bmi = parseFloat(data.bmi)
				if (bmi > 24.9) {
					this.aiAdvice.push({
						icon: '🏃‍♂️',
						title: '减重建议',
						description: '建议每周减重0.5-1公斤，通过控制热量摄入和增加运动来实现。'
					})
				} else if (bmi < 18.5) {
					this.aiAdvice.push({
						icon: '💪',
						title: '增重建议',
						description: '建议适当增加热量摄入，进行力量训练来增加肌肉质量。'
					})
				}

				// 基于血压的建议
				if (data.bloodPressureStatus !== '正常') {
					this.aiAdvice.push({
						icon: '❤️',
						title: '血压管理',
						description: '建议低盐饮食，规律运动，保持良好作息，定期监测血压。'
					})
				}

				// 基于运动习惯的建议
				if (data.exercise === '30分钟以下') {
					this.aiAdvice.push({
						icon: '🚴‍♂️',
						title: '运动建议',
						description: '建议每天进行30-60分钟的中等强度有氧运动。'
					})
				}

				// 基于睡眠的建议
				if (data.sleep === '6小时以下') {
					this.aiAdvice.push({
						icon: '😴',
						title: '睡眠建议',
						description: '建议保证7-8小时充足睡眠，避免熬夜，建立规律的作息时间。'
					})
				}

				// 通用健康建议
				this.aiAdvice.push({
					icon: '🥗',
					title: '饮食建议',
					description: '建议均衡饮食，多吃蔬菜水果，适量蛋白质，少油少盐。'
				})

				this.aiAdvice.push({
					icon: '💧',
					title: '水分补充',
					description: '建议每天喝8杯水，保持身体水分充足。'
				})
			}
		}
	}
</script>

<style scoped>
	.container {
		padding: 20rpx;
		background-color: #f5f5f5;
		min-height: 100vh;
		position: relative;
	}

	.header {
		text-align: center;
		margin-bottom: 30rpx;
	}

	.title {
		font-size: 40rpx;
		font-weight: bold;
		color: #333;
		display: block;
		margin-bottom: 10rpx;
	}

	.subtitle {
		font-size: 26rpx;
		color: #666;
	}

	.data-check {
		background: white;
		border-radius: 15rpx;
		padding: 60rpx 40rpx;
		text-align: center;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.check-icon {
		font-size: 100rpx;
		margin-bottom: 20rpx;
	}

	.check-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		display: block;
		margin-bottom: 10rpx;
	}

	.check-desc {
		font-size: 26rpx;
		color: #666;
		display: block;
		margin-bottom: 30rpx;
	}

	.check-btn {
		background: linear-gradient(135deg, #4CAF50, #45a049);
		color: white;
		border: none;
		border-radius: 15rpx;
		padding: 20rpx 40rpx;
		font-size: 28rpx;
	}

	.score-section {
		background: white;
		border-radius: 15rpx;
		padding: 40rpx;
		margin-bottom: 20rpx;
		text-align: center;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.score-circle {
		margin-bottom: 20rpx;
	}

	.score-number {
		font-size: 80rpx;
		font-weight: bold;
		color: #4CAF50;
		display: block;
	}

	.score-label {
		font-size: 28rpx;
		color: #666;
	}

	.score-text {
		font-size: 28rpx;
		color: #333;
		line-height: 1.5;
	}

	.analysis-section {
		background: white;
		border-radius: 15rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.section-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 20rpx;
		display: block;
	}

	.analysis-item {
		margin-bottom: 25rpx;
		padding-bottom: 25rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}

	.analysis-item:last-child {
		border-bottom: none;
		margin-bottom: 0;
		padding-bottom: 0;
	}

	.item-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.item-title {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
	}

	.item-value {
		font-size: 28rpx;
		color: #4CAF50;
		font-weight: bold;
	}

	.item-desc {
		font-size: 26rpx;
		color: #666;
		line-height: 1.5;
	}

	.ai-advice-section {
		background: white;
		border-radius: 15rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.advice-list {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.advice-item {
		display: flex;
		align-items: flex-start;
		padding: 20rpx;
		background: #f8f9fa;
		border-radius: 10rpx;
	}

	.advice-icon {
		font-size: 40rpx;
		margin-right: 15rpx;
		margin-top: 5rpx;
	}

	.advice-content {
		flex: 1;
	}

	.advice-title {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
		display: block;
		margin-bottom: 5rpx;
	}

	.advice-desc {
		font-size: 24rpx;
		color: #666;
		line-height: 1.4;
	}

	.button-container {
		margin-bottom: 30rpx;
	}

	.analyze-btn {
		width: 100%;
		height: 90rpx;
		background: linear-gradient(135deg, #4CAF50, #45a049);
		color: white;
		border: none;
		border-radius: 15rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.clear-cache-btn {
		width: 49%;
		height: 90rpx;
		background: linear-gradient(135deg, #4CAF50, #45a049);
		color: white;
		border: none;
		border-radius: 15rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.cache-status {
		background: #fff3cd;
		border: 1rpx solid #ffeaa7;
		border-radius: 10rpx;
		padding: 20rpx;
		margin-bottom: 20rpx;
		text-align: center;
	}

	.status-text {
		font-size: 28rpx;
		color: #856404;
		display: block;
		margin-bottom: 10rpx;
	}

	.status-hint {
		font-size: 24rpx;
		color: #856404;
	}

	.loading-overlay {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.5);
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 999;
	}

	.loading-content {
		background: white;
		border-radius: 15rpx;
		padding: 40rpx;
		text-align: center;
	}

	.loading-icon {
		font-size: 80rpx;
		margin-bottom: 20rpx;
	}

	.loading-text {
		font-size: 28rpx;
		color: #333;
		display: block;
		margin-bottom: 10rpx;
	}

	.loading-subtext {
		font-size: 24rpx;
		color: #666;
	}

	.connection-status {
		background: #fff3cd;
		border: 1rpx solid #ffeaa7;
		border-radius: 10rpx;
		padding: 20rpx;
		margin-top: 20rpx;
		text-align: center;
	}

	.warn-tip {
		color: #ff4757;
		background: #fff5f5;
		border-radius: 10rpx;
		padding: 20rpx;
		margin: 20rpx 0;
		font-size: 28rpx;
		text-align: center;
	}

	.history-tip {
		color: #666;
		background: #fff5f5;
		border-radius: 10rpx;
		padding: 20rpx;
		margin: 20rpx 0;
		font-size: 28rpx;
		text-align: center;
	}
</style>